Kotlin

Functional (SAM) interfaces

Swift
                  fun interface KRunnable {
   fun invoke()
}
                

SAM conversions

                  fun interface IntPredicate {
   fun accept(i: Int): Boolean
}
                
                  // Creating an instance of a class
val isEven = object : IntPredicate {
   override fun accept(i: Int): Boolean {
       return i % 2 == 0
   }
}
                
                  // Creating an instance using lambda
val isEven = IntPredicate { it % 2 == 0 }
                
👏
                  fun interface IntPredicate {
   fun accept(i: Int): Boolean
}
​
val isEven = IntPredicate { it % 2 == 0 }
​
fun main() {
   println("Is 7 even? - ${isEven.accept(7)}")
}